*************************************************************
* Title: 5_pre_analysis_plan								*
* Authors: Peter Kuhn, Trevor Osaki, Lei Yue                *
* Purpose: Pre-Analysis Plan Exercises (standardized)       *
* Date: September 2024                                      *
*************************************************************


********* PRELIMINARY SET-UP *********
version 16

* Set your directory where you store the data

clear

	cap cd $homedir
	cap cd "2_Main Analyses"

* IN
loc DTA_MAIN "d1_when_is_discrimination_unfair_data_set"
	
	
/* BRING DATA: d1_when_is_discrimination_unfair_data_set
------------------------------------------------------------------------------- */
use "`DTA_MAIN'", replace

********* GEN VARS *********

	* Transform fairness variables (i.e., standardized and/or re-scale "fair" and "BRO" measures)
	egen sfair = std(fair)
	egen sbro = std(bro)
	gen bro2 = bro 
	replace bro = bro + 4

	* Set up threshold for BRO measure here -- used to investigate BBU
	gen bmo = (bro > 3)
	gen bfo = (bro <= 3)

	* Create variables specific to PAP
	gen employer_taste = (low_just == 1 & taste == 1)
	gen customer_taste = (low_just == 0 & taste == 1)

	gen inaccurate_stat = (low_just == 1 & taste == 0)
	gen accurate_stat = (low_just == 0 & taste == 0)
	
	drop party
	gen party = (party_republican == 1)
	replace party = 2 if party_indep_other == 1
	replace party = 3 if party_democrat == 1

	gen views = (conserv == 1)
	replace views = 2 if mod == 1
	replace views = 3 if lib == 1
	
	gen party_others = party_indep_other
	gen education_collegefour = education_four_college
	
	gen SL = stat*inaccurate_stat
	gen TE = taste*employer_taste
	gen Bdem = party_democrat*black
	gen Brep = party_republican*black
	gen Bindep = party_independent*black
	gen Bother_party = party_other*black
	gen Bmale = male*black
	gen B_age18_24 = age18_24*black
	gen B_age25_34 = age25_34*black
	gen B_age35_44 = age35_44*black
	gen B_age45_54 = age45_54*black
	gen B_age55_64 = age55_64*black
	gen B_age65_74 = age65_74*black
	gen Bwhite = race_white*black
	gen Bblack = race_black*black
	gen Basian = race_asian*black
	gen Bhispanic = race_hispanic*black
	gen Bindigenous = race_indigenous*black
	gen Bislander = race_islander*black
	gen Botherrace = race_other*black

	gen Bindep_other = black*party_indep_other
	gen Bother = black*other
	gen Blib = black*lib
	gen Bconserv = black*conserv
	gen Bmod = black*mod
	gen B_age55_over = black*age55_over
	gen Bfour_college = education_four_college*black
	gen Bhigher = education_higher*black
	gen B_age18_34 = age18_34*black
	
	gen Bother_race = other*black

	gen BFO_B = bfo*black
	gen BMO_B = bmo*black

*** Stage One: Establishing the Main Fact ***

********** Table P1.1 ********** 

	lab var taste "Taste-based"
	lab var employer_taste "Taste-based x Employer"
	lab var inaccurate_stat "Statistical x Low-quality"
	lab var black "Black discriminatee"

	* Is Taste-Based Discrimination Seen as Less Fair than Statistical Discrimination?
	// (1)
	reg sfair taste, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word ctitle(All) replace 

	* How Do People Respond to Sub-types of Taste-Based and Statistical Discrimination?
	// (2)
	reg sfair employer_taste if stat == 0,cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word append ctitle(All)
	// (3)
	reg sfair inaccurate_stat if stat == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word append ctitle(All)

	* Do People React Differently to Discrimination Against their Own Race versus Other Races?
	// (4)
	reg sfair black,cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word append ctitle(All) 
	// (5)
	reg sfair black if race_white == 1, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word append ctitle(White) 
	// (6)
	reg sfair black if non_white == 1, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_1", word append ctitle(Non-white) label
	

********** Table P1.4 ********** 

	lab var race_black "Black respondent"
	lab var other "Other race respondent"
	lab var male "Male"
	lab var age35_44 "Age 35-44"
	lab var age45_54 "Age 45-54"
	lab var age55_over "Age 55 and over"
	lab var party_democrat "Democrat"
	lab var party_indep_other "Independent or other party"
	lab var lib "Liberal"
	lab var mod "Moderate"
	lab var education_four_college "Four-year college or university"
	lab var education_higher "Graduate School"

	* Determinants of Black People's Perceived Relative Opportunities (BRO)
	reg sbro race_black other male age35_44 age45_54 age55_over party_democrat party_indep_other lib mod education_four_college education_higher if ordering == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP1_4", word label replace 

********** Table P1.5 ********** 

	* Determinants of Discriminatee Race Effect (DRE)
	lab var SL "Statistical x Low-quality"
	lab var TE "Taste-based x Employer"
	lab var Bblack "Black Discriminatee x Black respondent"
	lab var Bother "Black Discriminatee x Other race respondent"
	lab var Bmale "Black Discriminatee x Male respondent"
	lab var B_age35_44 "Black Discriminatee x Age35-44"
	lab var B_age45_54 "Black Discriminatee x Age45-54"
	lab var B_age55_over "Black Discriminatee x Age 55 and over"
	lab var Bdem "Black Discriminatee x Democrat"
	lab var Bindep_other "Black Discriminatee x Independent or other party"
	lab var Blib "Black Discriminatee x Liberal"
	lab var Bmod "Black Discriminatee x Moderate"
	lab var Bfour_college "Black Discriminatee x Four-year college"
	lab var Bhigher "Black Discriminatee x Graduate School"

estimates clear
	eststo: reg sfair taste SL TE black race_black other male age35_44 age45_54 age55_over party_democrat party_indep_other lib mod education_four_college education_higher Bblack Bother Bmale B_age35_44 B_age45_54 B_age55_over Bdem Bindep_other Blib Bmod Bfour_college Bhigher, cluster(randomid)
	eststo: reg sfair taste SL TE black race_black other male age35_44 age45_54 age55_over party_democrat party_indep_other lib mod education_four_college education_higher Bblack Bother Bmale B_age35_44 B_age45_54 B_age55_over Bdem Bindep_other Blib Bmod Bfour_college Bhigher, cluster(randomid)

// 	outreg2 using "PAP/pap_TableP1_5", label word replace 

#delim ;
	esttab using "PAP/pap_TableP1_5.rtf", replace 
 	    label nomtitle legend
		       
        cells("b(fmt(%8.4f) star pattern(1 0)) se(fmt(%8.4f) par pattern(0 1))")
		
		star(* 0.10 ** 0.05 *** 0.01)
		
		stats(N r2, fmt(0 3) 
           labels("Observations" "R-squared"))
		
		title("Table P1.5: How Does Racial Bias in Fairness Assessments vary with Respondent Characteristics?")

		collabels("Coefficient" "Standard Error")
		
		addnotes(" " "Notes: This table contains the results of estimating equation (2) from the pre-analysis plan. One star indicates a ten percent significance level, two stars indicate a five percent level, and three stars indicate a one percent level. Standard errors are clustered by the respondent.")        
		
		refcat(taste "A. Treatment Effects:"
			   race_black "B. Respondent Characteristics:"
			   Bblack "C. Race Treatment Interactions with Respondent Characteristics:", nolabel)
        ;
#delim cr


********** Table P1.6 ********** 
	* The Relative Importance of "Actions" versus "Identity"
	lab var race_white "White respondent"
	lab var Bwhite "Black discriminatee x White Respondent"
	
	reg sfair taste SL TE race_white race_black Bwhite Bother Bblack, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_6", word replace ctitle("Actions & Identity")

	reg sfair taste SL TE, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_6", word append ctitle("Actions")

	reg sfair race_white race_black Bwhite Bother Bblack, cluster(randomid)
	outreg2 using "PAP/pap_TableP1_6", word append ctitle("Identity") label




*** Stage Two: Models of Fairness ***

********** Table P2.1 ********** 
	* Exploring Some Simple Models of Subjective Fairness 
	
	// (1)
	reg sfair taste SL TE black,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word replace ctitle("All") addtext(Respondent FE, NO) 
	// (2)
	reg sfair taste SL TE black i.randomid,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word append ctitle("All") addtext(Respondent FE, YES) keep(taste SL TE black)
	// (3)
	reg sfair taste SL TE black if race_white == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word append ctitle("White") addtext(Respondent FE, NO)
	// (4)
	reg sfair taste SL TE black i.randomid if race_white == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word append ctitle("White") addtext(Respondent FE, YES) keep(taste SL TE black)
	// (5)
	reg sfair taste SL TE black if non_white == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word append ctitle("Non-White") addtext(Respondent FE, NO)
	// (6)
	reg fair taste SL TE black i.randomid if non_white == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_1", word append ctitle("Non-White") addtext(Respondent FE, YES) label keep(taste SL TE black)
	

	

********** Table P2.4 ********** 
	* A Hybrid Model: Conditional Utilitarianism
	
	lab var bmo "BMO (delta1)"
	lab var BFO_B "BFO x Black discriminatee (delta2)"
	lab var BMO_B "BMO x Black discriminatee (delta3)"
	// (1)
	reg sfair taste SL TE bmo BFO_B BMO_B, cluster(randomid)
	outreg2 using "PAP/pap_TableP2_4", word replace ctitle("All respondents")
	// (2)
	reg sfair taste SL TE bmo BFO_B BMO_B if race_white == 1, cluster(randomid)
	outreg2 using "PAP/pap_TableP2_4", word append ctitle("White respondents")
	// (3)
	reg sfair taste SL TE bmo BFO_B BMO_B if non_white == 1, cluster(randomid) 
	outreg2 using "PAP/pap_TableP2_4", word append ctitle("Non-white respondents") label

	
********** Table P2.5 ********** 
	* Interactions between Distributional Considerations and Concerns for Procedural Fairness 
	
	// (1)
	reg sfair taste SL TE black,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_5", word replace ctitle("Full Sample") addtext(Respondent FE, NO) 
	// (2)
	reg sfair taste SL TE black i.randomid,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_5", word append ctitle("Within-subject") addtext(Respondent FE, YES) keep(taste SL TE black)
	// (3)
	reg sfair taste SL TE black if stage_one == 1,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_5", word append ctitle("Stage 1 (Between-subject)") addtext(Respondent FE, NO)
	// (4)
	reg sfair taste SL TE black if stage_one == 0,cluster(randomid)
	outreg2 using "PAP/pap_TableP2_5", word append ctitle("Stage 2 (Between-subject)") addtext(Respondent FE, NO) label
	
	
******** Robustness Check *********

********** Table P3.1 ********** 
	* "Thoughtful" Respondents
	
	// (1)
	reg sfair taste SL TE black,cluster(randomid)
	outreg2 using "PAP/pap_TableP3_1", word replace ctitle("Full sample") addtext(Respondent FE, NO) 
	// (2)
	reg sfair taste SL TE black i.randomid,cluster(randomid) 
	outreg2 using "PAP/pap_TableP3_1", word append ctitle("Full sample")  keep(taste SL TE black) addtext(Respondent FE, YES) 
	// (3)
	reg sfair taste SL TE black if durationinseconds > 502, cluster(randomid)
	outreg2 using "PAP/pap_TableP3_1", word append ctitle(`""Thoughtful" sample"') addtext(Respondent FE, NO) 
	// (4)
	reg sfair taste SL TE black i.randomid if durationinseconds > 502, cluster(randomid)
	outreg2 using "PAP/pap_TableP3_1", word append ctitle(`""Thoughtful" sample"') label keep(taste SL TE black) addtext(Respondent FE, YES) 
